package com.yanqu.road.server.pb.orewar;

import com.yanqu.road.entity.crossorewar.CrossOreStationInfo;
import com.yanqu.road.entity.crossorewar.CrossOreWarNotice;
import com.yanqu.road.entity.crossorewar.CrossOreWarRecord;
import com.yanqu.road.entity.crossorewar.CrossUserOrePit;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.pb.orewar.OreWarProto;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

import java.util.List;

public class CrossOreWarPb {

    public static OreWarProto.CrossOreTopBuildingDetailRespMsg.Builder parseCrossOreTopBuildingDetailRespMsg(List<CrossUserOrePit> crossUserOrePitList){
        OreWarProto.CrossOreTopBuildingDetailRespMsg.Builder respMsg = OreWarProto.CrossOreTopBuildingDetailRespMsg.newBuilder();
        respMsg.setRet(0);
        if(null != crossUserOrePitList){
            for(CrossUserOrePit crossUserOrePit : crossUserOrePitList){
                if(crossUserOrePit.getUserId() != 0){
                    OreWarProto.CrossOrePitTempMsg.Builder msg = parseCrossOrePitTempMsg(crossUserOrePit);
                    if(null != msg){
                        respMsg.addOrePitList(msg);
                    }
                }
            }
        }
        return respMsg;
    }

    //跨服的用户坑位详细信息
    public static OreWarProto.CrossOrePitListMsg.Builder parseCrossOrePitListMsg(List<CrossUserOrePit> crossUserOrePitList){
        OreWarProto.CrossOrePitListMsg.Builder listMsg = OreWarProto.CrossOrePitListMsg.newBuilder();
        if(null != crossUserOrePitList){
            for(CrossUserOrePit crossUserOrePit : crossUserOrePitList){
                OreWarProto.CrossOrePitTempMsg.Builder msg = parseCrossOrePitTempMsg(crossUserOrePit);
                if(null != msg){
                    listMsg.addOrePitList(msg);
                }
            }
        }
        return listMsg;
    }

    //生成本服盐场一致的协议返回到指定服务器直接下发客户端
    public static OreWarProto.OrePitTempMsg.Builder parseOrePitTempMsg(CrossUserOrePit crossUserOrePit) {
        if(null == crossUserOrePit){
            return null;
        }
        OreWarProto.OrePitTempMsg.Builder msg = OreWarProto.OrePitTempMsg.newBuilder();
        msg.setActivityId(crossUserOrePit.getActivityId());
        msg.setPitId(crossUserOrePit.getPitId());
        msg.setStationId(crossUserOrePit.getStationId());
        msg.setUserId(crossUserOrePit.getUserId());
        msg.setNickName(crossUserOrePit.getNickName());
        msg.setDecoration(crossUserOrePit.getUserBaseInfo().getDecoration());
        msg.setTitleId(crossUserOrePit.getUserBaseInfo().getTitleId());
        msg.setCity(crossUserOrePit.getUserBaseInfo().getCity());
        msg.setUnionName(crossUserOrePit.getUserBaseInfo().getUnionName());
        msg.setUnionUid(crossUserOrePit.getUserBaseInfo().getUnionUid());
        msg.setServerId(crossUserOrePit.getServerId());
        return msg;
    }


    //同步跨服坑位信息
    public static OreWarProto.CrossOrePitSyncMsg.Builder parseCrossOrePitSyncMsg(int activityId,List<CrossUserOrePit> crossUserOrePitList){
        OreWarProto.CrossOrePitSyncMsg.Builder msg = OreWarProto.CrossOrePitSyncMsg.newBuilder();
        msg.setActivityId(activityId);
        for(CrossUserOrePit crossUserOrePit : crossUserOrePitList){
            msg.addCrossOrePitList(parseCrossOrePitTempMsg(crossUserOrePit));
        }
        return msg;
    }

    public static OreWarProto.CrossOreStationSyncMsg.Builder parseCrossStationSyncMsg(int activityId,List<CrossOreStationInfo> crossOreStationInfoList,int groupId){
        OreWarProto.CrossOreStationSyncMsg.Builder msg = OreWarProto.CrossOreStationSyncMsg.newBuilder();
        msg.setActivityId(activityId);
        for(CrossOreStationInfo crossOreStationInfo : crossOreStationInfoList){
            msg.addCrossOreStation(parseCrossStationTempMsg(crossOreStationInfo));
        }
        msg.setGroupId(groupId);
        return msg;
    }

    public static OreWarProto.CrossOreStationTempMsg.Builder parseCrossStationTempMsg(CrossOreStationInfo crossOreStationInfo){
        if(null == crossOreStationInfo){
            return null;
        }
        OreWarProto.CrossOreStationTempMsg.Builder msg = OreWarProto.CrossOreStationTempMsg.newBuilder();
        msg.setActivityId(crossOreStationInfo.getActivityId());
        msg.setStationId(crossOreStationInfo.getStationId());
        msg.setOccupyCount(crossOreStationInfo.getOccupyCount());
        msg.setAverageAbility(crossOreStationInfo.getAverageAbility().toString());
        msg.setIsBlowout(crossOreStationInfo.isBlowout());
        msg.setNameServerId(crossOreStationInfo.getServerId());
        msg.setUnionUid(crossOreStationInfo.getUnionUid());
        msg.setUnionName(crossOreStationInfo.getUnionName());
        msg.addAllUserId(crossOreStationInfo.getUserIdList());
        return msg;
    }

    //跨服同步坑位信息到本服
    public static OreWarProto.CrossOrePitTempMsg.Builder parseCrossOrePitTempMsg(CrossUserOrePit crossUserOrePit){
        if(null == crossUserOrePit){
            return null;
        }
        OreWarProto.CrossOrePitTempMsg.Builder msg = OreWarProto.CrossOrePitTempMsg.newBuilder();
        msg.setActivityId(crossUserOrePit.getActivityId());
        msg.setPitId(crossUserOrePit.getPitId());
        msg.setStationId(crossUserOrePit.getStationId());
        msg.setUserId(crossUserOrePit.getUserId());
        msg.setNickName(crossUserOrePit.getNickName());
        msg.setPatronsInfoStr(crossUserOrePit.getPatronsInfoStr());
        msg.setJoinTime(crossUserOrePit.getJoinTime());
        msg.setLastGetRewardTime(crossUserOrePit.getLastGetRewardTime());
        msg.setIsBlowout(crossUserOrePit.isBlowout());
        msg.setPlayerBaseData(PlayerBasePb.parsePlayerBaseTempMsg(crossUserOrePit.getUserBaseInfo()));
        msg.setServerId(crossUserOrePit.getServerId());
        return msg;
    }

    //被打玩家记录信息
    public static OreWarProto.CrossRecordSyncMsg.Builder parseCrossRecordSyncMsg(int activityId,List<CrossOreWarRecord> crossOreWarRecordList,int groupId){
        OreWarProto.CrossRecordSyncMsg.Builder msg = OreWarProto.CrossRecordSyncMsg.newBuilder();
        msg.setActivityId(activityId);
        for(CrossOreWarRecord crossOreWarRecord : crossOreWarRecordList){
            msg.addRecordList(parseCrossOreWarRecordTempMsg(crossOreWarRecord));
        }
        msg.setGroupId(groupId);
        return msg;
    }

    //被打玩家记录信息
    public static OreWarProto.CrossRecordSyncMsg.Builder parseCrossRecordSyncMsg(int activityId,CrossOreWarRecord crossOreWarRecord,int groupId){
        OreWarProto.CrossRecordSyncMsg.Builder msg = OreWarProto.CrossRecordSyncMsg.newBuilder();
        msg.setActivityId(activityId);
        msg.addRecordList(parseCrossOreWarRecordTempMsg(crossOreWarRecord));
        msg.setGroupId(groupId);
        return msg;
    }

    private static OreWarProto.CrossOreWarRecordTempMsg.Builder parseCrossOreWarRecordTempMsg(CrossOreWarRecord crossOreWarRecord){
        OreWarProto.CrossOreWarRecordTempMsg.Builder msg = OreWarProto.CrossOreWarRecordTempMsg.newBuilder();
        msg.setRecordUid(crossOreWarRecord.getRecordUid());
        msg.setActivityId(crossOreWarRecord.getActivityId());
        msg.setUserId(crossOreWarRecord.getUserId());
        msg.setServerId(crossOreWarRecord.getServerId());
        msg.setPitId(crossOreWarRecord.getPitId());
        msg.setEnemyUserId(crossOreWarRecord.getEnemyUserId());
        msg.setEnemyBaseData(PlayerBasePb.parsePlayerBaseTempMsg(crossOreWarRecord.getEnemyBaseData()));
        msg.setRecordTime(crossOreWarRecord.getRecordTime());
        msg.setIsWin(crossOreWarRecord.isWin());
        return msg;
    }


    //同步跨服notice(所有战斗信息)信息
    public static OreWarProto.CrossNoticeSyncMsg.Builder parseCrossOreWarNoticeSyncMsg(int activityId, List<CrossOreWarNotice> crossOreWarNoticeList,int groupId){
        OreWarProto.CrossNoticeSyncMsg.Builder msg = OreWarProto.CrossNoticeSyncMsg.newBuilder();
        msg.setActivityId(activityId);
        for(CrossOreWarNotice crossOreWarNotice : crossOreWarNoticeList){
            msg.addNoticeList(parseCrossOreWarNoticeTempMsg(crossOreWarNotice));
        }
        msg.setGroupId(groupId);
        return msg;
    }

    //跨服同步坑位信息到本服
    private static OreWarProto.CrossOreWarNoticeTempMsg.Builder parseCrossOreWarNoticeTempMsg(CrossOreWarNotice crossOreWarNotice){
        if(null == crossOreWarNotice){
            return null;
        }
        OreWarProto.CrossOreWarNoticeTempMsg.Builder msg = OreWarProto.CrossOreWarNoticeTempMsg.newBuilder();
        msg.setNoticeUid(crossOreWarNotice.getNoticeUid());
        msg.setActivityId(crossOreWarNotice.getActivityId());
        msg.setPitId(crossOreWarNotice.getPitId());
        msg.setNoticeTime(crossOreWarNotice.getNoticeTime());
        msg.setUserId(crossOreWarNotice.getUserId());
        msg.setServerId(crossOreWarNotice.getServerId());
        msg.setPlayerBaseData(PlayerBasePb.parsePlayerBaseTempMsg(crossOreWarNotice.getUserBaseInfo()));
        msg.setEnemyUserId(crossOreWarNotice.getEnemyUserId());
        msg.setEnemyBaseData(PlayerBasePb.parsePlayerBaseTempMsg(crossOreWarNotice.getEnemyBaseInfo()));
        return msg;
    }

    public static OreWarProto.CrossSystemRecallMailMsg.Builder parseCrossSystemRecallMailMsg(int activityId, long userId, Property reward,long recallTime,List<CrossUserOrePit> crossUserOrePitList,int groupId){
        OreWarProto.CrossSystemRecallMailMsg.Builder msg = OreWarProto.CrossSystemRecallMailMsg.newBuilder();
        msg.setActivityId(activityId);
        msg.setUserId(userId);
        msg.setReward(PropertyHelper.parsePropertyToString(reward));
        msg.setRecallTime(recallTime);
        for(CrossUserOrePit crossUserOrePit : crossUserOrePitList){
            msg.addOrePitList(parseCrossOrePitTempMsg(crossUserOrePit));
        }
        msg.setGroupId(groupId);
        return msg;
    }


    //跨服井喷通知各个区服发送消息
    public static OreWarProto.CrossNotifyBlowoutMessage.Builder parseCrossNotifyBlowoutMsg(int activityId,int groupId){
        OreWarProto.CrossNotifyBlowoutMessage.Builder msg = OreWarProto.CrossNotifyBlowoutMessage.newBuilder();
        msg.setActivityId(activityId);
        msg.setGroupId(groupId);
        return msg;
    }
}
